package org.example.warehouse.controller.front;

import org.example.core.utils.R;
import org.example.warehouse.service.WareSkuService;
import org.example.warehouse.vo.LockedStockVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @author 小杰_cc
 * @version 1.0
 */
@RestController
@RequestMapping("/wms/front/sku")
public class WareSkuFrontController {

    @Autowired
    private WareSkuService wareSkuService;

    /**
     * 锁定库存
     * @param vo
     * @return
     */
    @PostMapping("/stock")
    public R<?> lockedStock(@RequestBody LockedStockVo vo) {
        wareSkuService.lockStock(vo);
        return R.ok();
    }

    /**
     * 判断skus是否有库存
     * @param skuIds
     * @return
     */
    @GetMapping("/hasStocks")
    public R<Map<Long, Integer>> queryStocks(@RequestParam("skuIds") List<Long> skuIds){
        Map<Long, Integer> stock = wareSkuService.querySkusIsStocks(skuIds);
        return R.ok(stock);
    }

    /**
     * 查询单个sku的库存数
     */
    @GetMapping("/stock/{skuId}")
    public R<Integer> queryStock(@PathVariable("skuId") Long skuId){
        Integer stock = wareSkuService.queryStock(skuId);
        return R.ok(stock);
    }
}